home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / scrollkeeper / stylesheets / index.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2007-03-09  |  10.0 KB  |  234 lines

  1. <?xml version='1.0'?>
  2. <!DOCTYPE xsl:stylesheet [
  3. <!ENTITY sep '" "'>
  4. <!ENTITY comma '", "'>
  5. ]>
  6.  
  7. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
  8.  
  9. <!-- copyright (c) 2001 Sun Microsystems, Inc. -->
  10.  
  11. <xsl:output method="xml" indent="yes"/>
  12.  
  13.  
  14. <xsl:key name="primary"
  15.          match="indexterm[@id | @zone | see]" 
  16.          use="normalize-space(primary)"/>
  17.  
  18. <xsl:key name="secondary"
  19.          match="indexterm[@id | @zone | see]" 
  20.          use="normalize-space(concat(primary, &sep;, secondary))"/>
  21.  
  22. <xsl:key name="tertiary"
  23.          match="indexterm[@id | @zone | see]" 
  24.          use="normalize-space(concat(primary, &sep;, secondary, &sep;, tertiary))"/>
  25.  
  26. <xsl:key name="primary-section"
  27.          match="indexterm[@id | @zone and not(secondary) and not(see)]"
  28.          use="@id|@zone"/>
  29.  
  30. <xsl:key name="secondary-section"
  31.          match="indexterm[@id | @zone and not(tertiary) and not(see)]"
  32.          use="normalize-space(concat(primary, &sep;, secondary))"/>
  33.  
  34. <xsl:key name="tertiary-section"
  35.      match="indexterm[@id | @zone and not(see)]"
  36.      use="normalize-space(concat(primary, &sep;, secondary, &sep;, tertiary))"/>
  37.  
  38. <xsl:key name="primary-term"
  39.          match="indexterm[@id | @zone and not(secondary) and not(see)]"
  40.          use="normalize-space(primary)"/>
  41.  
  42. <xsl:key name="see-also"
  43.      match="indexterm[seealso]"
  44.      use="normalize-space(concat(primary, &sep;, secondary, &sep;, tertiary, &sep;, seealso))"/>
  45.  
  46. <xsl:key name="see"
  47.      match="indexterm[see]"
  48.      use="normalize-space(concat(primary, &sep;, secondary, &sep;, tertiary, &sep;, see))"/>
  49.  
  50. <xsl:key name="see-reference"
  51.      match="indexterm"
  52.      use="normalize-space(translate(see|seealso, '",', &sep;))"/>
  53.  
  54.  
  55. <xsl:template match="/">
  56.     <indexdoc>
  57.         <xsl:apply-templates select="//indexterm[@id | @zone | see and count(.|key('primary', primary)[1])=1]" mode="index-primary">
  58.            <xsl:sort select="primary"/>
  59.         </xsl:apply-templates>
  60.     </indexdoc>
  61. </xsl:template>
  62.  
  63.  
  64. <xsl:template match="indexterm" mode="index-primary">
  65.    <indexitem>
  66.       <xsl:variable name="key" select="normalize-space(primary)"/>
  67.       <xsl:variable name="refs" select="key('primary', $key)"/>
  68.       <title><xsl:value-of select="primary"/></title>
  69.       <xsl:for-each select="$refs[key('primary-section', @id|@zone)]">
  70.          <link><xsl:attribute name="linkid">
  71.                    <xsl:value-of select="@id|@zone"/>
  72.         </xsl:attribute>
  73.             <xsl:if test="key('see-reference', $key)">
  74.                 <xsl:attribute name="indexid">
  75.                    <xsl:value-of select="generate-id(key('primary-term', $key)[1])"/>
  76.                 </xsl:attribute> 
  77.             </xsl:if>
  78.           </link>
  79.        </xsl:for-each>
  80.        <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::see or self::seealso]">
  81.             <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', normalize-space(concat(primary, &sep;, &sep;, &sep;, see)))[1])]"
  82.                        mode="index-see">
  83.                 <xsl:sort select="see"/>
  84.             </xsl:apply-templates>
  85.             <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', normalize-space(concat(primary, &sep;, &sep;, &sep;, seealso)))[1])]"
  86.                        mode="index-seealso">
  87.                <xsl:sort select="seealso"/>
  88.             </xsl:apply-templates>
  89.             <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', normalize-space(concat($key, &sep;, secondary)))[1]) = 1]"
  90.                              mode="index-secondary">
  91.                <xsl:sort select="secondary"/>
  92.          </xsl:apply-templates>
  93.          </xsl:if>    
  94.      </indexitem>
  95. </xsl:template>
  96.  
  97. <xsl:template match="indexterm" mode="index-secondary">
  98.    <indexitem>
  99.       <xsl:variable name="key" select="normalize-space(concat(primary, &sep;, secondary))"/>
  100.       <xsl:variable name="refs" select="key('secondary', $key)"/>
  101.       <title><xsl:value-of select="secondary"/></title>
  102.       <xsl:for-each select="$refs[key('secondary-section', $key)]">
  103.          <link><xsl:attribute name="linkid">
  104.                    <xsl:value-of select="@id|@zone"/>
  105.         </xsl:attribute>
  106.             <xsl:if test="key('see-reference', $key)">
  107.                 <xsl:attribute name="indexid">
  108.                    <xsl:value-of select="generate-id(key('secondary-section', $key)[1])"/>
  109.                 </xsl:attribute> 
  110.             </xsl:if>
  111.           </link>
  112.        </xsl:for-each>
  113.       <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::see or self::seealso]">
  114.          <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', normalize-space(concat(primary, &sep;, secondary, &sep;, &sep;, see)))[1])]"
  115.                        mode="index-see">
  116.             <xsl:sort select="see"/>
  117.          </xsl:apply-templates>
  118.          <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', normalize-space(concat(primary, &sep;, secondary, &sep;, &sep;, seealso)))[1])]"
  119.                        mode="index-seealso">
  120.             <xsl:sort select="seealso"/>
  121.          </xsl:apply-templates>
  122.          <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary',
  123. normalize-space(concat($key, &sep;, tertiary)))[1]) = 1]"
  124.                              mode="index-tertiary">
  125.             <xsl:sort select="tertiary"/>
  126.          </xsl:apply-templates>
  127.      </xsl:if>    
  128.    </indexitem>
  129. </xsl:template>
  130.  
  131. <xsl:template match="indexterm" mode="index-tertiary">
  132.    <indexitem>
  133.       <xsl:variable name="key" select="normalize-space(concat(primary, &sep;, secondary, &sep;, tertiary))"/>
  134.       <xsl:variable name="refs" select="key('tertiary', $key)"/>
  135.       <title><xsl:value-of select="tertiary"/></title>
  136.       <xsl:for-each select="$refs[key('tertiary-section', $key)]">
  137.          <link><xsl:attribute name="linkid">
  138.                    <xsl:value-of select="@id|@zone"/>
  139.         </xsl:attribute>
  140.             <xsl:if test="key('see-reference', $key)">
  141.                 <xsl:attribute name="indexid">
  142.                    <xsl:value-of select="generate-id(key('tertiary-section', $key)[1])"/>
  143.                 </xsl:attribute> 
  144.             </xsl:if>
  145.           </link>
  146.        </xsl:for-each>
  147.       <xsl:variable name="reference" select="$refs/seealso | $refs/see"/>
  148.       <xsl:if test="$reference">
  149.         <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', normalize-space(concat(primary, &sep;, secondary, &sep;, tertiary, &sep;, see)))[1])]"
  150.                       mode="index-see">
  151.            <xsl:sort select="see"/>
  152.         </xsl:apply-templates>
  153.         <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', normalize-space(concat(primary, &sep;, secondary, &sep;, tertiary, &sep;, seealso)))[1])]"
  154.                        mode="index-seealso">
  155.              <xsl:sort select="seealso"/>
  156.          </xsl:apply-templates>
  157.       </xsl:if>
  158.    </indexitem>
  159. </xsl:template>
  160.  
  161. <xsl:template match="indexterm" mode="index-see">
  162.    <xsl:variable name="key" select="normalize-space(translate(see, '"', &sep;))"/>
  163.    <xsl:choose>
  164.       <xsl:when test="not(contains($key, ','))">
  165.          <see><xsl:attribute name="indexid">
  166.         <xsl:value-of select="generate-id(key('primary-term', $key)[1])"/>
  167.         </xsl:attribute>
  168.         <xsl:value-of select="$key"/>
  169.          </see>
  170.       </xsl:when>
  171.       <xsl:otherwise>
  172.          <xsl:variable name="first-term" select="normalize-space(substring-before($key, ','))"/>
  173.          <xsl:variable name="rest" select="normalize-space(substring-after($key, ','))"/>
  174.          <xsl:choose>
  175.             <xsl:when test="substring-after($rest, ',')">
  176.                <xsl:variable name="second-term" select="normalize-space(substring-before($rest, ','))"/>
  177.                <xsl:variable name="third-term" select="normalize-space(substring-after($rest, ','))"/>
  178.                <see><xsl:attribute name="indexid">
  179.             <xsl:value-of select="generate-id(key('tertiary-section', concat($first-term, &sep;, $second-term, &sep;, $third-term))[1])"/>
  180.             </xsl:attribute>
  181.             <xsl:value-of select="concat($first-term, ,, $second-term, ,, $third-term)"/>
  182.         </see>
  183.             </xsl:when>
  184.             <xsl:otherwise>
  185.                <see><xsl:attribute name="indexid">
  186.                 <xsl:value-of select="generate-id(key('secondary-section', concat($first-term, &sep;, $rest))[1])"/>
  187.                 </xsl:attribute>
  188.                 <xsl:value-of select="concat($first-term, ,, $rest)"/>
  189.            </see>
  190.              </xsl:otherwise>
  191.           </xsl:choose>
  192.       </xsl:otherwise>
  193.     </xsl:choose>
  194. </xsl:template>
  195.  
  196. <xsl:template match="indexterm" mode="index-seealso">
  197.    <xsl:variable name="key" select="normalize-space(translate(seealso, '"', &sep;))"/>
  198.    <xsl:choose>
  199.     <xsl:when test="not(contains($key, ','))">
  200.      <seealso><xsl:attribute name="indexid">
  201.             <xsl:value-of select="generate-id(key('primary-term', $key)[1])"/>
  202.             </xsl:attribute>
  203.             <xsl:value-of select="$key"/>
  204.      </seealso>
  205.     </xsl:when>
  206.     <xsl:otherwise>
  207.      <xsl:variable name="first-term" select="normalize-space(substring-before($key, ','))"/>
  208.      <xsl:variable name="rest" select="normalize-space(substring-after($key, ','))"/>
  209.      <xsl:choose>
  210.             <xsl:when test="substring-after($rest, ',')">
  211.         <xsl:variable name="second-term" select="normalize-space(substring-before($rest, ','))"/>
  212.                 <xsl:variable name="third-term" select="normalize-space(substring-after($rest, ','))"/>
  213.         <seealso><xsl:attribute name="indexid">
  214.                     <xsl:value-of select="generate-id(key('tertiary-section', concat($first-term, &sep;, $second-term, &sep;, $third-term))[1])"/>
  215.                     </xsl:attribute>
  216.                     <xsl:value-of select="concat($first-term, ,, $second-term, ,, $third-term)"/>
  217.         </seealso>
  218.             </xsl:when>
  219.             <xsl:otherwise>
  220.         <seealso><xsl:attribute name="indexid">
  221.                     <xsl:value-of select="generate-id(key('secondary-section', concat($first-term, &sep;, $rest))[1])"/>
  222.                        </xsl:attribute>
  223.                     <xsl:value-of select="concat($first-term, ,, $rest)"/>
  224.         </seealso>
  225.              </xsl:otherwise>
  226.       </xsl:choose>
  227.     </xsl:otherwise>
  228.     </xsl:choose>
  229. </xsl:template>
  230.  
  231.  
  232.  
  233. </xsl:stylesheet>
  234.